package demo02;
//寻找数组中间下标
public class Solution {
    public int[] arr = new int[]{1,1,2,2,2,1,1};
    public int function(){
        //处理前缀dp数组
        int L = arr.length;
        int[] f = new int[L];
        f[0] = 0;
        for (int i = 1; i < L; i++) {
            f[i] = f[i - 1] + arr[i - 1];
        }
        //处理后缀数组
        int[] g = new int[L];
        g[L-1] = 0;
        for (int j = L-2; j >=0 ; j--) {
            g[j] = g[j+1] + arr[j+1];
        }
        for (int k = 0; k < L-1; k++) {
            if (f[k] == g[k]) return k;
        }
        return -1;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.function());
    }
}
